using System.Collections.Generic;
using UnityEngine;

public class BottlesManager : MonoBehaviour
{
	private List<BottleController> bottles = new List<BottleController>();

	private ButtonsPickLiquidManager buttonsPickLiquidManager;

	private BottleController currentBottle;

	public void Awake()
	{
		buttonsPickLiquidManager = UnityEngine.Object.FindObjectOfType<ButtonsPickLiquidManager>();
	}

	public void DeleteBottles()
	{
		for (int i = 0; i < bottles.Count; i++)
		{
			UnityEngine.Object.Destroy(bottles[i].gameObject);
		}
		bottles.Clear();
	}

	public void CreateBottles(List<LiquidType> types, Transform glassFront)
	{
		DeleteBottles();
		for (int i = 0; i < types.Count; i++)
		{
			string text = "Bottle_" + types[i].ToString();
			GameObject original = Resources.Load<GameObject>("Prefabs/Bottles/" + text);
			GameObject gameObject = UnityEngine.Object.Instantiate(original);
			gameObject.name = text;
			BottleController component = gameObject.GetComponent<BottleController>();
			component.SetGlassTransform(glassFront);
			component.SetOnBottleSlideOutAction(OnBottleSlideOut);
			gameObject.transform.position = component.startPosition;
			bottles.Add(component);
		}
	}

	public void OnBottleSlideOut()
	{
		buttonsPickLiquidManager.ZoomOutAllButtons();
	}

	public void ShowBottle(LiquidType type)
	{
		string a = type.ToString();
		for (int i = 0; i < bottles.Count; i++)
		{
			string b = bottles[i].name.Split('_')[1];
			if (a == b)
			{
				bottles[i].SlideInAnimation();
				currentBottle = bottles[i];
			}
			else
			{
				bottles[i].SlideOutAnimation();
			}
		}
	}

	public void SlideOutCurrentBottleEndLevel()
	{
		if (currentBottle != null)
		{
			currentBottle.enabledObject = false;
		}
	}
}
